package com.czy.service.impl;

import com.czy.mapper.ClazzMapper;
import com.czy.mapper.EmpMapper;
import com.czy.mapper.StudentMapper;
import com.czy.pojo.CountOption;
import com.czy.pojo.JobOption;
import com.czy.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private EmpMapper empMapper;

    @Autowired
    private StudentMapper studentMapper;

    @Autowired
    private ClazzMapper clazzMapper;

    @Override
    public JobOption getEmpJobData() {
        //调用mapper接口，获取统计数据
        //map：pos=教研主管，num=1
        List<Map<String, Object>> list = empMapper.countEmpJobData();

        //组装结果，并返回
        List<Object> jobList = list.stream().map(dataMap -> dataMap.get("pos")).toList();
        List<Object> dataList = list.stream().map(dataMap -> dataMap.get("num")).toList();

        return new JobOption(jobList,dataList);
    }

    @Override
    public List<Map<String, Object>> getGenderData() {
        return empMapper.countEmpGenderData();
    }

    @Override
    public List<Map<String, Object>> getDegreeData() {
        //调用mapper接口，获取统计数据
        List<Map<String,Object>> list = studentMapper.countDegreeData();
        return list;
    }

    @Override
    public CountOption getStudentCountData() {
        //调用mapper接口，获取统计数据
        List<Map<String,Object>> countList =  studentMapper.getStudentCountData();

        List<Object> clazzList = countList.stream().map(dataMap -> dataMap.get("clazzId")).toList();
        List<Object> dataList = countList.stream().map(dataMap -> dataMap.get("num")).toList();

        //将 clazzList 里面的班级 id 转换为 班级名
        List<Object> nameList = clazzMapper.getClazzName(clazzList);

        //组装结果，并返回
        return new CountOption(nameList,dataList);
    }
}
